import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/user/login/index.vue'
import layout from '../views/layout/index.vue'
import { routerList } from '@/utils/utils'
import screen from '../views/largeScreen/index.vue'
import editScreen from '../views/largeScreen/editScreen.vue'
import realIndex from '../views/largeScreen/realIndex.vue'
import demo from '../views/largeScreen/demo.vue'
import demo1 from '../views/largeScreen/demo1.vue'
import creditDemo from '../views/creditScreen/creditDemo.vue'
import demoDet from '../views/largeScreenDet/demo.vue'
import realIndexLishui from '../views/largeScreen/realIndexLishui.vue'
import llSantai from '../views/largeScreenSant/llSantai.vue'
import santai from '../views/largeScreenSant/santai.vue'
Vue.use(VueRouter)
const files = require.context('.', true, /\.js$/)
let routers = []
files.keys().forEach(key => {
  if (key === './index.js') return

  routers = routers.concat(files(key).default)
})

const routes = [
  {
    path: '/user/login',
    name: 'Login',
    component: login,
  },
  {
    path: '/screen',
    name: 'Screen',
    component: screen,
  },
  {
    path: '/editScreen',
    name: 'EditScreen',
    component: editScreen,
  },
  {
    path: '/realIndex',
    name: 'RealIndex',
    component: realIndex,
  },
  {
    path: '/demo',
    name: 'Demo',
    component: demo,
  },
  {
    path: '/demoDet',
    name: 'DemoDet',
    component: demoDet,
  },
  {
    path: '/realIndexLishui',
    name: 'realIndexLishui',
    component: realIndexLishui,
  },

  {
    path: '/demo1',
    name: 'Demo1',
    component: demo1,
  },
  {
    path: '/creditDemo',
    name: 'CreditDemo',
    component: creditDemo,
  },

  {
    path: '/',
    name: 'layout',
    component: layout,
    // redirect: '/audit-model/credit-extension',
    children: [...routers],
  },
  {
    path: '/llSantai',
    name: 'llSantai',
    component: llSantai,
  },
  {
    path: '/santai',
    name: 'santai',
    component: santai,
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.NODE_ENV === 'production' ? process.env.VUE_APP_API_BASE_URL : '/',
  routes,
})
router.beforeEach(async (to, from, next) => {
  routerList(to)
  next()
})
export default router
